<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>/home/zjh/git/Koala-UI/KoalaUI/WebContent/lib/Koala_ColorPicker.js</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
    <script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
</head>
<body class="yui3-skin-sam">

<div id="doc">
    <div id="hd" class="yui3-g header">
        <div class="yui3-u-3-4">
            
                <h1><img src="../assets/css/logo.png" title=""></h1>
            
        </div>
        <div class="yui3-u-1-4 version">
            <em>API Docs for: </em>
        </div>
    </div>
    <div id="bd" class="yui3-g">

        <div class="yui3-u-1-4">
            <div id="docs-sidebar" class="sidebar apidocs">
                <div id="api-list">
    <h2 class="off-left">APIs</h2>
    <div id="api-tabview" class="tabview">
        <ul class="tabs">
            <li><a href="#api-classes">Classes</a></li>
            <li><a href="#api-modules">Modules</a></li>
        </ul>

        <div id="api-tabview-filter">
            <input type="search" id="api-filter" placeholder="Type to filter APIs">
        </div>

        <div id="api-tabview-panel">
            <ul id="api-classes" class="apis classes">
            
                <li><a href="../classes/Accordion.html">Accordion</a></li>
            
                <li><a href="../classes/AutoComplete.html">AutoComplete</a></li>
            
                <li><a href="../classes/Button.html">Button</a></li>
            
                <li><a href="../classes/Carousel.html">Carousel</a></li>
            
                <li><a href="../classes/ColorPicker.html">ColorPicker</a></li>
            
                <li><a href="../classes/Combobox.html">Combobox</a></li>
            
                <li><a href="../classes/DateTimePicker.html">DateTimePicker</a></li>
            
                <li><a href="../classes/Grid.html">Grid</a></li>
            
                <li><a href="../classes/ListView.html">ListView</a></li>
            
                <li><a href="../classes/Popover.html">Popover</a></li>
            
                <li><a href="../classes/ProgressBar.html">ProgressBar</a></li>
            
                <li><a href="../classes/RichTextEditor.html">RichTextEditor</a></li>
            
                <li><a href="../classes/ScrollSpy.html">ScrollSpy</a></li>
            
                <li><a href="../classes/Select.html">Select</a></li>
            
                <li><a href="../classes/SideBar.html">SideBar</a></li>
            
                <li><a href="../classes/Slider.html">Slider</a></li>
            
                <li><a href="../classes/Spinner.html">Spinner</a></li>
            
                <li><a href="../classes/Tab.html">Tab</a></li>
            
                <li><a href="../classes/ToolBar.html">ToolBar</a></li>
            
                <li><a href="../classes/Tooltip.html">Tooltip</a></li>
            
                <li><a href="../classes/Tree.html">Tree</a></li>
            
                <li><a href="../classes/Wizard.html">Wizard</a></li>
            
            </ul>

            <ul id="api-modules" class="apis modules">
            
            </ul>
        </div>
    </div>
</div>

            </div>
        </div>
        <div class="yui3-u-3-4">
                <div id="api-options">
        Show:
        <label for="api-show-inherited">
            <input type="checkbox" id="api-show-inherited" checked>
            Inherited
        </label>

        <label for="api-show-protected">
            <input type="checkbox" id="api-show-protected">
            Protected
        </label>

        <label for="api-show-private">
            <input type="checkbox" id="api-show-private">
            Private
        </label>
        <label for="api-show-deprecated">
            <input type="checkbox" id="api-show-deprecated">
            Deprecated
        </label>

    </div>


            <div class="apidocs">
                <div id="docs-main">
                    <div class="content">
                        <h1 class="file-heading">File: /home/zjh/git/Koala-UI/KoalaUI/WebContent/lib/Koala_ColorPicker.js</h1>

<div class="file">
    <pre class="code prettyprint linenums">
/**
 *
 * Color picker
 * Author: Stefan Petre www.eyecon.ro
 * 
 * Dual licensed under the MIT and GPL licenses
 * 
 */
+(function ($) {
	&quot;use strict&quot;;
	
	/**
	 * 颜色选择器，来自www.eyecon.ro
	 * @class ColorPicker
	 * @constructor 
	 * @example
	 * 	js代码
	 * 	$(function(){
			$(&#x27;#colorpickerField1&#x27;).ColorPicker({
				onChange: function(hsb, hex, rgb, el) {
					$(&quot;#colorpickerField1&quot;).val(hex);
					//$(this).ColorPickerHide();
				},
				onBeforeShow: function () {
					$(this).ColorPickerSetColor(this.value);
				}
			})
		})
		
		html代码
		#&lt;input type=&quot;text&quot; value=&quot;00ff00&quot; id=&quot;colorpickerField1&quot; size=&quot;6&quot; maxlength=&quot;6&quot;&gt;
	 */
	var ColorPicker = function () {
		var
			ids = {},
			inAction,
			charMin = 65,
			visible,
			tpl = &#x27;&lt;div class=&quot;colorpicker&quot;&gt;&lt;div class=&quot;colorpicker_color&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;colorpicker_hue&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;colorpicker_new_color&quot;&gt;&lt;/div&gt;&lt;div class=&quot;colorpicker_current_color&quot;&gt;&lt;/div&gt;&lt;div class=&quot;colorpicker_hex&quot;&gt;&lt;input type=&quot;text&quot; maxlength=&quot;6&quot; size=&quot;6&quot; /&gt;&lt;/div&gt;&lt;div class=&quot;colorpicker_rgb_r colorpicker_field&quot;&gt;&lt;input type=&quot;text&quot; maxlength=&quot;3&quot; size=&quot;3&quot; /&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;colorpicker_rgb_g colorpicker_field&quot;&gt;&lt;input type=&quot;text&quot; maxlength=&quot;3&quot; size=&quot;3&quot; /&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;colorpicker_rgb_b colorpicker_field&quot;&gt;&lt;input type=&quot;text&quot; maxlength=&quot;3&quot; size=&quot;3&quot; /&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;colorpicker_hsb_h colorpicker_field&quot;&gt;&lt;input type=&quot;text&quot; maxlength=&quot;3&quot; size=&quot;3&quot; /&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;colorpicker_hsb_s colorpicker_field&quot;&gt;&lt;input type=&quot;text&quot; maxlength=&quot;3&quot; size=&quot;3&quot; /&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;colorpicker_hsb_b colorpicker_field&quot;&gt;&lt;input type=&quot;text&quot; maxlength=&quot;3&quot; size=&quot;3&quot; /&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;colorpicker_submit&quot;&gt;&lt;/div&gt;&lt;/div&gt;&#x27;,
			defaults = {
				/**
				 * 显示ColorPicker的事件
				 * @property eventName
				 * @type String
				 * @default &#x27;click&#x27;
				 */
				eventName: &#x27;click&#x27;,
				/**
				 * 显示颜色选择器的回调函数
				 * @property onShow
				 * @type Function
				 * @default function () {}
				 */
				onShow: function () {},
				/**
				 * 显示颜色选择器之前的回调函数
				 * @property onBeforeShow
				 * @type Function
				 * @default function () {}
				 */
				onBeforeShow: function(){},
				/**
				 * 隐藏颜色选择器的回调函数
				 * @property onHide
				 * @type Function
				 * @default function () {}
				 */
				onHide: function () {},
				/**
				 * 颜色选择器内部改变值时的回调函数
				 * @property onChange
				 * @type Function
				 * @default function () {}
				 */
				onChange: function () {},
				/**
				 * 提交时的回调函数
				 * @property onSubmit
				 * @type Function
				 * @default function () {}
				 */
				onSubmit: function () {},
				/**
				 * 默认颜色
				 * @property color
				 * @type String
				 * @default &#x27;ff0000&#x27;
				 */
				color: &#x27;ff0000&#x27;,
				/**
				 * 是否预览
				 * @property livePreview
				 * @type Boolean
				 * @default true
				 */
				livePreview: true,
//				/**
//				 * 
//				 * @property flat
//				 * @type Function
//				 * @default function () {}
//				 */
				flat: false
			},
			fillRGBFields = function  (hsb, cal) {
				var rgb = HSBToRGB(hsb);
				$(cal).data(&#x27;colorpicker&#x27;).fields
					.eq(1).val(rgb.r).end()
					.eq(2).val(rgb.g).end()
					.eq(3).val(rgb.b).end();
			},
			fillHSBFields = function  (hsb, cal) {
				$(cal).data(&#x27;colorpicker&#x27;).fields
					.eq(4).val(hsb.h).end()
					.eq(5).val(hsb.s).end()
					.eq(6).val(hsb.b).end();
			},
			fillHexFields = function (hsb, cal) {
				$(cal).data(&#x27;colorpicker&#x27;).fields
					.eq(0).val(HSBToHex(hsb)).end();
			},
			setSelector = function (hsb, cal) {
				$(cal).data(&#x27;colorpicker&#x27;).selector.css(&#x27;backgroundColor&#x27;, &#x27;#&#x27; + HSBToHex({h: hsb.h, s: 100, b: 100}));
				$(cal).data(&#x27;colorpicker&#x27;).selectorIndic.css({
					left: parseInt(150 * hsb.s/100, 10),
					top: parseInt(150 * (100-hsb.b)/100, 10)
				});
			},
			setHue = function (hsb, cal) {
				$(cal).data(&#x27;colorpicker&#x27;).hue.css(&#x27;top&#x27;, parseInt(150 - 150 * hsb.h/360, 10));
			},
			setCurrentColor = function (hsb, cal) {
				$(cal).data(&#x27;colorpicker&#x27;).currentColor.css(&#x27;backgroundColor&#x27;, &#x27;#&#x27; + HSBToHex(hsb));
			},
			setNewColor = function (hsb, cal) {
				$(cal).data(&#x27;colorpicker&#x27;).newColor.css(&#x27;backgroundColor&#x27;, &#x27;#&#x27; + HSBToHex(hsb));
			},
			keyDown = function (ev) {
				var pressedKey = ev.charCode || ev.keyCode || -1;
				if ((pressedKey &gt; charMin &amp;&amp; pressedKey &lt;= 90) || pressedKey == 32) {
					return false;
				}
				var cal = $(this).parent().parent();
				if (cal.data(&#x27;colorpicker&#x27;).livePreview === true) {
					change.apply(this);
				}
			},
			change = function (ev) {
				var cal = $(this).parent().parent(), col;
				if (this.parentNode.className.indexOf(&#x27;_hex&#x27;) &gt; 0) {
					cal.data(&#x27;colorpicker&#x27;).color = col = HexToHSB(fixHex(this.value));
				} else if (this.parentNode.className.indexOf(&#x27;_hsb&#x27;) &gt; 0) {
					cal.data(&#x27;colorpicker&#x27;).color = col = fixHSB({
						h: parseInt(cal.data(&#x27;colorpicker&#x27;).fields.eq(4).val(), 10),
						s: parseInt(cal.data(&#x27;colorpicker&#x27;).fields.eq(5).val(), 10),
						b: parseInt(cal.data(&#x27;colorpicker&#x27;).fields.eq(6).val(), 10)
					});
				} else {
					cal.data(&#x27;colorpicker&#x27;).color = col = RGBToHSB(fixRGB({
						r: parseInt(cal.data(&#x27;colorpicker&#x27;).fields.eq(1).val(), 10),
						g: parseInt(cal.data(&#x27;colorpicker&#x27;).fields.eq(2).val(), 10),
						b: parseInt(cal.data(&#x27;colorpicker&#x27;).fields.eq(3).val(), 10)
					}));
				}
				if (ev) {
					fillRGBFields(col, cal.get(0));
					fillHexFields(col, cal.get(0));
					fillHSBFields(col, cal.get(0));
				}
				setSelector(col, cal.get(0));
				setHue(col, cal.get(0));
				setNewColor(col, cal.get(0));
				cal.data(&#x27;colorpicker&#x27;).onChange.apply(cal, [col, HSBToHex(col), HSBToRGB(col)]);
			},
			blur = function (ev) {
				var cal = $(this).parent().parent();
				cal.data(&#x27;colorpicker&#x27;).fields.parent().removeClass(&#x27;colorpicker_focus&#x27;);
			},
			focus = function () {
				charMin = this.parentNode.className.indexOf(&#x27;_hex&#x27;) &gt; 0 ? 70 : 65;
				$(this).parent().parent().data(&#x27;colorpicker&#x27;).fields.parent().removeClass(&#x27;colorpicker_focus&#x27;);
				$(this).parent().addClass(&#x27;colorpicker_focus&#x27;);
			},
			downIncrement = function (ev) {
				var field = $(this).parent().find(&#x27;input&#x27;).focus();
				var current = {
					el: $(this).parent().addClass(&#x27;colorpicker_slider&#x27;),
					max: this.parentNode.className.indexOf(&#x27;_hsb_h&#x27;) &gt; 0 ? 360 : (this.parentNode.className.indexOf(&#x27;_hsb&#x27;) &gt; 0 ? 100 : 255),
					y: ev.pageY,
					field: field,
					val: parseInt(field.val(), 10),
					preview: $(this).parent().parent().data(&#x27;colorpicker&#x27;).livePreview					
				};
				$(document).bind(&#x27;mouseup&#x27;, current, upIncrement);
				$(document).bind(&#x27;mousemove&#x27;, current, moveIncrement);
			},
			moveIncrement = function (ev) {
				ev.data.field.val(Math.max(0, Math.min(ev.data.max, parseInt(ev.data.val + ev.pageY - ev.data.y, 10))));
				if (ev.data.preview) {
					change.apply(ev.data.field.get(0), [true]);
				}
				return false;
			},
			upIncrement = function (ev) {
				change.apply(ev.data.field.get(0), [true]);
				ev.data.el.removeClass(&#x27;colorpicker_slider&#x27;).find(&#x27;input&#x27;).focus();
				$(document).unbind(&#x27;mouseup&#x27;, upIncrement);
				$(document).unbind(&#x27;mousemove&#x27;, moveIncrement);
				return false;
			},
			downHue = function (ev) {
				var current = {
					cal: $(this).parent(),
					y: $(this).offset().top
				};
				current.preview = current.cal.data(&#x27;colorpicker&#x27;).livePreview;
				$(document).bind(&#x27;mouseup&#x27;, current, upHue);
				$(document).bind(&#x27;mousemove&#x27;, current, moveHue);
			},
			moveHue = function (ev) {
				change.apply(
					ev.data.cal.data(&#x27;colorpicker&#x27;)
						.fields
						.eq(4)
						.val(parseInt(360*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.y))))/150, 10))
						.get(0),
					[ev.data.preview]
				);
				return false;
			},
			upHue = function (ev) {
				fillRGBFields(ev.data.cal.data(&#x27;colorpicker&#x27;).color, ev.data.cal.get(0));
				fillHexFields(ev.data.cal.data(&#x27;colorpicker&#x27;).color, ev.data.cal.get(0));
				$(document).unbind(&#x27;mouseup&#x27;, upHue);
				$(document).unbind(&#x27;mousemove&#x27;, moveHue);
				return false;
			},
			downSelector = function (ev) {
				var current = {
					cal: $(this).parent(),
					pos: $(this).offset()
				};
				current.preview = current.cal.data(&#x27;colorpicker&#x27;).livePreview;
				$(document).bind(&#x27;mouseup&#x27;, current, upSelector);
				$(document).bind(&#x27;mousemove&#x27;, current, moveSelector);
			},
			moveSelector = function (ev) {
				change.apply(
					ev.data.cal.data(&#x27;colorpicker&#x27;)
						.fields
						.eq(6)
						.val(parseInt(100*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.pos.top))))/150, 10))
						.end()
						.eq(5)
						.val(parseInt(100*(Math.max(0,Math.min(150,(ev.pageX - ev.data.pos.left))))/150, 10))
						.get(0),
					[ev.data.preview]
				);
				return false;
			},
			upSelector = function (ev) {
				fillRGBFields(ev.data.cal.data(&#x27;colorpicker&#x27;).color, ev.data.cal.get(0));
				fillHexFields(ev.data.cal.data(&#x27;colorpicker&#x27;).color, ev.data.cal.get(0));
				$(document).unbind(&#x27;mouseup&#x27;, upSelector);
				$(document).unbind(&#x27;mousemove&#x27;, moveSelector);
				return false;
			},
			enterSubmit = function (ev) {
				$(this).addClass(&#x27;colorpicker_focus&#x27;);
			},
			leaveSubmit = function (ev) {
				$(this).removeClass(&#x27;colorpicker_focus&#x27;);
			},
			clickSubmit = function (ev) {
				var cal = $(this).parent();
				var col = cal.data(&#x27;colorpicker&#x27;).color;
				cal.data(&#x27;colorpicker&#x27;).origColor = col;
				setCurrentColor(col, cal.get(0));
				cal.data(&#x27;colorpicker&#x27;).onSubmit(col, HSBToHex(col), HSBToRGB(col), cal.data(&#x27;colorpicker&#x27;).el);
			},
			show = function (ev) {
				var cal = $(&#x27;#&#x27; + $(this).data(&#x27;colorpickerId&#x27;));
				cal.data(&#x27;colorpicker&#x27;).onBeforeShow.apply(this, [cal.get(0)]);
				var pos = $(this).offset();
				var viewPort = getViewport();
				var top = pos.top + this.offsetHeight;
				var left = pos.left;
				if (top + 176 &gt; viewPort.t + viewPort.h) {
					top -= this.offsetHeight + 176;
				}
				if (left + 356 &gt; viewPort.l + viewPort.w) {
					left -= 356;
				}
				cal.css({left: left + &#x27;px&#x27;, top: top + &#x27;px&#x27;});
				if (cal.data(&#x27;colorpicker&#x27;).onShow.apply(this, [cal.get(0)]) != false) {
					cal.show();
				}
				$(document).bind(&#x27;mousedown&#x27;, {cal: cal}, hide);
				return false;
			},
			hide = function (ev) {
				if (!isChildOf(ev.data.cal.get(0), ev.target, ev.data.cal.get(0))) {
					if (ev.data.cal.data(&#x27;colorpicker&#x27;).onHide.apply(this, [ev.data.cal.get(0)]) != false) {
						ev.data.cal.hide();
					}
					$(document).unbind(&#x27;mousedown&#x27;, hide);
				}
			},
			isChildOf = function(parentEl, el, container) {
				if (parentEl == el) {
					return true;
				}
				if (parentEl.contains) {
					return parentEl.contains(el);
				}
				if ( parentEl.compareDocumentPosition ) {
					return !!(parentEl.compareDocumentPosition(el) &amp; 16);
				}
				var prEl = el.parentNode;
				while(prEl &amp;&amp; prEl != container) {
					if (prEl == parentEl)
						return true;
					prEl = prEl.parentNode;
				}
				return false;
			},
			getViewport = function () {
				var m = document.compatMode == &#x27;CSS1Compat&#x27;;
				return {
					l : window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft),
					t : window.pageYOffset || (m ? document.documentElement.scrollTop : document.body.scrollTop),
					w : window.innerWidth || (m ? document.documentElement.clientWidth : document.body.clientWidth),
					h : window.innerHeight || (m ? document.documentElement.clientHeight : document.body.clientHeight)
				};
			},
			fixHSB = function (hsb) {
				return {
					h: Math.min(360, Math.max(0, hsb.h)),
					s: Math.min(100, Math.max(0, hsb.s)),
					b: Math.min(100, Math.max(0, hsb.b))
				};
			}, 
			fixRGB = function (rgb) {
				return {
					r: Math.min(255, Math.max(0, rgb.r)),
					g: Math.min(255, Math.max(0, rgb.g)),
					b: Math.min(255, Math.max(0, rgb.b))
				};
			},
			fixHex = function (hex) {
				var len = 6 - hex.length;
				if (len &gt; 0) {
					var o = [];
					for (var i=0; i&lt;len; i++) {
						o.push(&#x27;0&#x27;);
					}
					o.push(hex);
					hex = o.join(&#x27;&#x27;);
				}
				return hex;
			}, 
			HexToRGB = function (hex) {
				var hex = parseInt(((hex.indexOf(&#x27;#&#x27;) &gt; -1) ? hex.substring(1) : hex), 16);
				return {r: hex &gt;&gt; 16, g: (hex &amp; 0x00FF00) &gt;&gt; 8, b: (hex &amp; 0x0000FF)};
			},
			HexToHSB = function (hex) {
				return RGBToHSB(HexToRGB(hex));
			},
			RGBToHSB = function (rgb) {
				var hsb = {
					h: 0,
					s: 0,
					b: 0
				};
				var min = Math.min(rgb.r, rgb.g, rgb.b);
				var max = Math.max(rgb.r, rgb.g, rgb.b);
				var delta = max - min;
				hsb.b = max;
				if (max != 0) {
					
				}
				hsb.s = max != 0 ? 255 * delta / max : 0;
				if (hsb.s != 0) {
					if (rgb.r == max) {
						hsb.h = (rgb.g - rgb.b) / delta;
					} else if (rgb.g == max) {
						hsb.h = 2 + (rgb.b - rgb.r) / delta;
					} else {
						hsb.h = 4 + (rgb.r - rgb.g) / delta;
					}
				} else {
					hsb.h = -1;
				}
				hsb.h *= 60;
				if (hsb.h &lt; 0) {
					hsb.h += 360;
				}
				hsb.s *= 100/255;
				hsb.b *= 100/255;
				return hsb;
			},
			HSBToRGB = function (hsb) {
				var rgb = {};
				var h = Math.round(hsb.h);
				var s = Math.round(hsb.s*255/100);
				var v = Math.round(hsb.b*255/100);
				if(s == 0) {
					rgb.r = rgb.g = rgb.b = v;
				} else {
					var t1 = v;
					var t2 = (255-s)*v/255;
					var t3 = (t1-t2)*(h%60)/60;
					if(h==360) h = 0;
					if(h&lt;60) {rgb.r=t1;	rgb.b=t2; rgb.g=t2+t3}
					else if(h&lt;120) {rgb.g=t1; rgb.b=t2;	rgb.r=t1-t3}
					else if(h&lt;180) {rgb.g=t1; rgb.r=t2;	rgb.b=t2+t3}
					else if(h&lt;240) {rgb.b=t1; rgb.r=t2;	rgb.g=t1-t3}
					else if(h&lt;300) {rgb.b=t1; rgb.g=t2;	rgb.r=t2+t3}
					else if(h&lt;360) {rgb.r=t1; rgb.g=t2;	rgb.b=t1-t3}
					else {rgb.r=0; rgb.g=0;	rgb.b=0}
				}
				return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)};
			},
			RGBToHex = function (rgb) {
				var hex = [
					rgb.r.toString(16),
					rgb.g.toString(16),
					rgb.b.toString(16)
				];
				$.each(hex, function (nr, val) {
					if (val.length == 1) {
						hex[nr] = &#x27;0&#x27; + val;
					}
				});
				return hex.join(&#x27;&#x27;);
			},
			HSBToHex = function (hsb) {
				return RGBToHex(HSBToRGB(hsb));
			},
			restoreOriginal = function () {
				var cal = $(this).parent();
				var col = cal.data(&#x27;colorpicker&#x27;).origColor;
				cal.data(&#x27;colorpicker&#x27;).color = col;
				fillRGBFields(col, cal.get(0));
				fillHexFields(col, cal.get(0));
				fillHSBFields(col, cal.get(0));
				setSelector(col, cal.get(0));
				setHue(col, cal.get(0));
				setNewColor(col, cal.get(0));
			};
		return {
			init: function (opt) {
				opt = $.extend({}, defaults, opt||{});
				if (typeof opt.color == &#x27;string&#x27;) {
					opt.color = HexToHSB(opt.color);
				} else if (opt.color.r != undefined &amp;&amp; opt.color.g != undefined &amp;&amp; opt.color.b != undefined) {
					opt.color = RGBToHSB(opt.color);
				} else if (opt.color.h != undefined &amp;&amp; opt.color.s != undefined &amp;&amp; opt.color.b != undefined) {
					opt.color = fixHSB(opt.color);
				} else {
					return this;
				}
				return this.each(function () {
					if (!$(this).data(&#x27;colorpickerId&#x27;)) {
						var options = $.extend({}, opt);
						options.origColor = opt.color;
						var id = &#x27;collorpicker_&#x27; + parseInt(Math.random() * 1000);
						$(this).data(&#x27;colorpickerId&#x27;, id);
						var cal = $(tpl).attr(&#x27;id&#x27;, id);
						if (options.flat) {
							cal.appendTo(this).show();
						} else {
							cal.appendTo(document.body);
						}
						options.fields = cal
											.find(&#x27;input&#x27;)
												.bind(&#x27;keyup&#x27;, keyDown)
												.bind(&#x27;change&#x27;, change)
												.bind(&#x27;blur&#x27;, blur)
												.bind(&#x27;focus&#x27;, focus);
						cal
							.find(&#x27;span&#x27;).bind(&#x27;mousedown&#x27;, downIncrement).end()
							.find(&#x27;&gt;div.colorpicker_current_color&#x27;).bind(&#x27;click&#x27;, restoreOriginal);
						options.selector = cal.find(&#x27;div.colorpicker_color&#x27;).bind(&#x27;mousedown&#x27;, downSelector);
						options.selectorIndic = options.selector.find(&#x27;div div&#x27;);
						options.el = this;
						options.hue = cal.find(&#x27;div.colorpicker_hue div&#x27;);
						cal.find(&#x27;div.colorpicker_hue&#x27;).bind(&#x27;mousedown&#x27;, downHue);
						options.newColor = cal.find(&#x27;div.colorpicker_new_color&#x27;);
						options.currentColor = cal.find(&#x27;div.colorpicker_current_color&#x27;);
						cal.data(&#x27;colorpicker&#x27;, options);
						cal.find(&#x27;div.colorpicker_submit&#x27;)
							.bind(&#x27;mouseenter&#x27;, enterSubmit)
							.bind(&#x27;mouseleave&#x27;, leaveSubmit)
							.bind(&#x27;click&#x27;, clickSubmit);
						fillRGBFields(options.color, cal.get(0));
						fillHSBFields(options.color, cal.get(0));
						fillHexFields(options.color, cal.get(0));
						setHue(options.color, cal.get(0));
						setSelector(options.color, cal.get(0));
						setCurrentColor(options.color, cal.get(0));
						setNewColor(options.color, cal.get(0));
						if (options.flat) {
							cal.css({
								position: &#x27;relative&#x27;,
								display: &#x27;block&#x27;
							});
						} else {
							$(this).bind(options.eventName, show);
						}
					}
				});
			},
			showPicker: function() {
				return this.each( function () {
					if ($(this).data(&#x27;colorpickerId&#x27;)) {
						show.apply(this);
					}
				});
			},
			hidePicker: function() {
				return this.each( function () {
					if ($(this).data(&#x27;colorpickerId&#x27;)) {
						$(&#x27;#&#x27; + $(this).data(&#x27;colorpickerId&#x27;)).hide();
					}
				});
			},
			setColor: function(col) {
				if (typeof col == &#x27;string&#x27;) {
					col = HexToHSB(col);
				} else if (col.r != undefined &amp;&amp; col.g != undefined &amp;&amp; col.b != undefined) {
					col = RGBToHSB(col);
				} else if (col.h != undefined &amp;&amp; col.s != undefined &amp;&amp; col.b != undefined) {
					col = fixHSB(col);
				} else {
					return this;
				}
				return this.each(function(){
					if ($(this).data(&#x27;colorpickerId&#x27;)) {
						var cal = $(&#x27;#&#x27; + $(this).data(&#x27;colorpickerId&#x27;));
						cal.data(&#x27;colorpicker&#x27;).color = col;
						cal.data(&#x27;colorpicker&#x27;).origColor = col;
						fillRGBFields(col, cal.get(0));
						fillHSBFields(col, cal.get(0));
						fillHexFields(col, cal.get(0));
						setHue(col, cal.get(0));
						setSelector(col, cal.get(0));
						setCurrentColor(col, cal.get(0));
						setNewColor(col, cal.get(0));
					}
				});
			}
		};
	}();
	$.fn.extend({
		ColorPicker: ColorPicker.init,
		ColorPickerHide: ColorPicker.hidePicker,
		ColorPickerShow: ColorPicker.showPicker,
		ColorPickerSetColor: ColorPicker.setColor
	});
})(jQuery);
    </pre>
</div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script src="../assets/js/yui-prettify.js"></script>
<script src="../assets/../api.js"></script>
<script src="../assets/js/api-filter.js"></script>
<script src="../assets/js/api-list.js"></script>
<script src="../assets/js/api-search.js"></script>
<script src="../assets/js/apidocs.js"></script>
</body>
</html>
